//
// Created by yewei on 2021/9/19.
//

#include <bits/stdc++.h>

using namespace std;

const int MAXV=30;
int postorder[MAXV];
int inorder[MAXV];

struct node{
    int data;
    node* left;
    node* right;
};

node* create(int postL, int postR, int inL, int inR);
void treeTrave(node* root);

int main(){
    freopen("../A1020.txt","r",stdin);
    int N;
    cin>>N;
    for(int i=1;i<=N;i++){
        cin>>postorder[i];
    }
    for(int i=1;i<=N;i++){
        cin>>inorder[i];
    }
    node* tree = create(1,N,1,N);
    treeTrave(tree);

    return 0;
}

node* create(int postL, int postR, int inL, int inR){
    if(postL>postR){
        return nullptr;
    }
    node* root = new node;
    root->data = postorder[postR];

    int k;
    for(k=inL;k<=inR;k++){
        if(inorder[k]==postorder[postR]) break;
    }
    int inLeft = k-inL;

    root->left = create(postL,postL+inLeft-1,inL,k-1);
    root->right = create(postL+inLeft,postR-1,k+1,inR);

    return root;
}

void treeTrave(node* root){
    queue<node*> q;
    q.push(root);
    int total = 0;
    while(!q.empty()){
        node* front = q.front();
        if(total++!=0) cout<<" ";
        cout<<front->data;
        q.pop();
        if(front->left!=nullptr) q.push(front->left);
        if(front->right!=nullptr) q.push(front->right);
    }
}